// Copyright 2012 dmitry.a.novikov@gmail.com
// 
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// 
// http://www.apache.org/licenses/LICENSE-2.0
// 
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// CnsZ::Exception and most common derrived exceptions declarations


#ifndef _INCLUDED_CNZ_CNSZ_EXCEPTION_H_
#define _INCLUDED_CNZ_CNSZ_EXCEPTION_H_

namespace CnsZ {

  class ValueString;
  class String;

  class Exception {
    P<Object> msg;
  public:
    Exception();
    Exception(const Object* m) : msg(m) {}
    P<Object> message() const;
  };

  class NotApplicable : public Exception {
  public:
    NotApplicable();
    NotApplicable(const Object* msg) : Exception(msg) {}
  };

  class NullFactory : public Exception {
  public:
    NullFactory();
    NullFactory(const Object* msg) : Exception(msg) {}
  };

  class InvalidArg : public Exception {
  public:
    InvalidArg();
    InvalidArg(const Object* msg) : Exception(msg) {}
  };

  class InvalidCast : public Exception {
  public:
    InvalidCast();
    InvalidCast(const Object* msg) : Exception(msg) {}
  };

  class NullPointer : public Exception {
  public:
    NullPointer();
    NullPointer(const Object* msg) : Exception(msg) {}
  };

  class IndexOutOfBounds : public Exception {
  public:
    IndexOutOfBounds();
    IndexOutOfBounds(const Object* msg) : Exception(msg) {}
  };

}

#define THROW_STATIC(EXCEPTIONCLASS,MESSAGE_CONTENT) \
    CNSZ_DEFINE_STATIC_STRING(msg,MESSAGE_CONTENT);\
    throw EXCEPTIONCLASS(CNSZ_GET_STATIC_STRING(msg))

#endif //#ifndef _INCLUDED_CNZ_CNSZ_EXCEPTION_H_